import CreateDatabase from "../components/createDatabase.vue"
import {
  createApp,
  createVNode,
  render
} from "vue"
import mNotice from '../components/index.js'
import TableTest from "../components/table-test.vue"

class ConnContextMenu {
  constructor(opt, params) {
    this.opt = opt;
    this.params = params
    this.node = params.node;
  }

  getMenus() {
    let menus = [];
    if (this.node && this.node.childrenLoaded) {
      menus.push({
        label: "关闭连接",
        click: () => {
          this.opt.bus.$emit(this.opt.constants.DELETE_NODE_CHILDREN, this.node)
        },
      })

    } else {
      menus.push({
        label: "打开连接",
        click: () => {
          this.opt.bus.$emit(this.opt.constants.REFRESH_NODE, this.node)
        },
      })
    }
    menus.push({
      label: "新建数据库",
      dividedTop: true,
      click: (event, item) => {
        this.opt.bus.$emit(this.opt.constants.CONTEXT_MENU_EVENT_KEY, {
          title: '新建数据库',
          component: CreateDatabase,
          data: this.node
        })
        return true;
      },
    })
    menus.push({
      label: "新建查询",
      click: () => {
        this.opt.bus.$emit(this.opt.constants.CONTEXT_MENU_EVENT_KEY, {
          type: this.opt.constants.CONTEXT_MENU_TYPE_TAGS_COM,
          title: '新建查询',
          id: this.node.data.id + "_sql_query",
          component: TableTest,
          data: this.node
        })
        return true;
      },
    })
    menus.push({
      label: "刷新",
      dividedTop: true,
      click: () => {
        return false;
      },
    })
    return menus
  }
}

export {
  ConnContextMenu
}